package cn.iocoder.yudao.module.crossborder.product.api;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.crossborder.product.api.dto.BrandDTO;
import cn.iocoder.yudao.module.crossborder.product.api.dto.CategoryDTO;
import cn.iocoder.yudao.module.crossborder.product.api.dto.ProductCreateReqDTO;
import cn.iocoder.yudao.module.crossborder.product.api.dto.ProductDTO;
import cn.iocoder.yudao.module.crossborder.product.service.ProductService;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;
import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

/**
 * 商品管理 API 接口实现类
 *
 * @author LHL
 */
@RestController // 提供 RESTful API 接口，给 Feign 调用
@Validated
public class ProductApiImpl implements ProductApi {

    @Resource
    private ProductService productService;

    @Override
    public CommonResult<ProductDTO> getProduct(Long id) {
        ProductDTO product = productService.getProduct(id);
        return success(product);
    }

    @Override
    public CommonResult<List<ProductDTO>> getProductList(List<Long> ids) {
        List<ProductDTO> products = productService.getProductList(ids);
        return success(products);
    }

    @Override
    public CommonResult<Long> createProduct(ProductCreateReqDTO createReq) {
        Long id = productService.createProduct(createReq);
        return success(id);
    }

    @Override
    public CommonResult<CategoryDTO> getCategory(Long id) {
        CategoryDTO category = productService.getCategory(id);
        return success(category);
    }

    @Override
    public CommonResult<List<CategoryDTO>> getCategoryList(List<Long> ids) {
        List<CategoryDTO> categories = productService.getCategoryList(ids);
        return success(categories);
    }

    @Override
    public CommonResult<BrandDTO> getBrand(Long id) {
        BrandDTO brand = productService.getBrand(id);
        return success(brand);
    }

    @Override
    public CommonResult<List<BrandDTO>> getBrandList(List<Long> ids) {
        List<BrandDTO> brands = productService.getBrandList(ids);
        return success(brands);
    }

    @Override
    public CommonResult<Boolean> updateStock(Long productId, Integer quantity) {
        Boolean result = productService.updateStock(productId, quantity);
        return success(result);
    }

    @Override
    public CommonResult<Boolean> updatePrice(Long productId, String price, String currency) {
        Boolean result = productService.updatePrice(productId, price, currency);
        return success(result);
    }

}
